﻿using Missbot.Common;
using MongoDB.Driver;

namespace Missbot.Service
{
    public class MongoContext : ISingleton
    {
        private readonly IMongoDatabase _Database;

        public MongoContext()
        {
            var mongoConnStr = Configger<AIConfigBase>.AIConfig.Mongo.MongoConnStr;
            var mongoDbName = Configger<AIConfigBase>.AIConfig.Mongo.MongoDbName;

            var client = new MongoClient(mongoConnStr);
            _Database = client.GetDatabase(mongoDbName);
        }

        public IMongoCollection<T> Collection<T>(string tableName = null)
        {
            return _Database.GetCollection<T>(string.IsNullOrEmpty(tableName) ? typeof(T).Name : tableName);
        }
    }
}
